//Immediately Invoked Function Expression (IIFE). An IIFE is a function that is immediately executed when it is defined.

( function( window, undefined ) {

    function clearAllCookies() {
          var cookies = document.cookie.split(";");
          for (var i = 0; i < cookies.length; i++) {
              var cookie = cookies[i].split("=");
                  cookie[1] = new Date(0).toUTCString();
                  cookies[i] = cookie.join("=");
                }
          document.cookie = cookies.join(";");
    }

    // we don't need call localStorage.removeItem("lastCheckin");
    console.log('all loalStorage has been cleared');
    localStorage.clear();

    clearAllCookies();
    console.log('all cookies has been cleared');

    /*
     * attetion:
     * 1) localStorage only support characters
     * 2) localStorage is shared in same browser
     *

    //save
    let tmUser = {name: 'Joe', age:32};
    let tmUserFile = JSON.stringify(tmUser);
    localStorage.setItem('tmUserFile', tmUserFile);

    //get
    tmUserFile = localStorage.getItem('tmUserFile');
    tmUser = JSON.parse(tmUserFile);
    console.log(tmUser);

    //expiration, if we dont' set it, it will be deleted in manually or out of space
    localStorage.setItem("key", "value", { expires: new Date(Date.now() + 1000 * 60 * 60 * 24) });
     *
     */

})( window );
